package com.wlz.java8.lambda.stream;

import com.wlz.java8.lambda.domain.Student;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author： wlz
 * @Date 2020/7/3 11:10
 * @description： TODO 原始做法
 * @version: 1.0
 */
public class Demo5 {

    List<Student> studentList =null;
    @Before
    public void before() {
        studentList = Arrays.asList(
                new Student("zhangsan", 15, 93),
                new Student("lisi", 16, 100),
                new Student("wangwu", 17, 86),
                new Student("zhaoliu", 13, 71),
                new Student("yuanqi", 14, 65)
        );
    }

    /**
     * 查询 成绩 > 70 的学生
     */
    @Test
    public void test() {
        List<Student> dataList = new ArrayList<>();
        for(Student student :studentList){
            if(student.getScore()>70){
                dataList.add(student);
            }
        }
        for(Student student :dataList){
            System.out.println(student);
        }
    }

    /**
     * 查找年龄>14的学生
     */
    @Test
    public void test2(){
        List<Student> dataList = new ArrayList<>();
        for(Student student :studentList){
            if(student.getAge()>14){
                dataList.add(student);
            }
        }
        for(Student student :dataList){
            System.out.println(student);
        }
    }

}
